package com.mi9688.stream;

import java.util.stream.Stream;

public class Sort {
    public static void main(String[] args) {
        // 创建一个包含整数的Stream
        Stream<Integer> stream1 = Stream.of(3, 1, 4, 1, 5, 9);
        Stream<Integer> stream2 = Stream.of(3, 1, 4, 1, 5, 9);

        // 使用sorted()方法对Stream1进行升序排序（默认）
        Stream<Integer> sortedStream = stream1.sorted();
        sortedStream.forEach(System.out::println);
        System.out.println("-----------------------------------------------");
        // 使用sorted()方法对Stream2进行降序排序
        Stream<Integer> sortedDescStream = stream2.sorted((a, b) -> b.compareTo(a));
        sortedDescStream.forEach(System.out::println);

    }
}
